package edu.caltech.android;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.google.android.c2dm.C2DMBaseReceiver;

import edu.caltech.android.c2dm.DeviceRegistrar;

public class C2DMReceiver extends C2DMBaseReceiver {
	private static final String TAG = "C2DMReceiver";

	public static final String GOT_C2DM = "edu.caltech.android.GOT_C2DM";	
	
	public C2DMReceiver() {
		super(DeviceRegistrar.SENDER_ID);
	}

	@Override
	public void onRegistered(Context context, String registrationId)
			throws java.io.IOException {
		//Log.d(TAG, "Registration ID arrived: " + registrationId);
		DeviceRegistrar.registerWithServer(context, registrationId);
	};

	@Override
	protected void onMessage(Context context, Intent intent) {
		//Log.e(TAG, "onMessage");

		Bundle extras = intent.getExtras();
		if (extras != null) {
			// TODO
		}
		
		Intent gotMessageIntent = new Intent(GOT_C2DM);
		gotMessageIntent.putExtra("Message", "message");
		context.sendBroadcast(gotMessageIntent);
		
	}

	@Override
	public void onError(Context context, String errorId) {
		Log.e(TAG, "Error occured! " + errorId);
	}

}
